1 /* file name : ArrayInstance.java
2 * authors : Christopher Ellsworth (Chris@chrisellsworth.com)
3 * created : 11/24/2002 02:33:59
4 * copyright :
5 *
6 * modifications:
7 *
8 * Make ArrayInstance and ObjectInstance siblings.
9 *
10 */
11 package jrre;
12
13 import jrre.types.*;
14
15 /***
16 *
17 *
18 * @author Christopher Ellsworth (Chris@chrisellsworth.com)
19 * @author Clarence Alston
20 */
21 public class ArrayInstance extends ObjectInstance {
22
23
24 private Type [] values;
25
26 public ArrayInstance(int type, int size){
27
28 super(0);
29
30 // 12 == ObjectRefernace
31 if(type == 12){
32 //values = new ReferenceType[size];
33 values = new Type[size];
34
35 for(int i=0;i < size;i++)
36 values[i] = new ReferenceType(null);
37 }
38 else if(type == 5){
39 //values = new CharType[size];
40 values = new Type[size];
41
42 /*
43 for(int i=0;i < size;i++)
44 values[i] = new CharType();
45 */
46 }
47 else{
48 //values = new PrimitiveType[size];
49 values = new Type[size];
50
51 for(int i=0;i < size;i++)
52 values[i] = new PrimitiveType(0);
53 }
54
55 //System.out.println("\n\n\nArrayInstance(type: "+type+" size: "+size+") "+toString());
56 }
57
58 public void setSize(int size){
59 values = new Type[size];
60 }
61
62 public int getSize(){
63 return values.length;
64 }
65
66 public void setValues(Type [] values){
67 this.values = values;
68 }
69
70 public Type [] getElements(){
71 return this.values;
72 }
73
74 public Type getElement(int index){
75 return values[index];
76 }
77
78 public void setElement(int index, Type value){
79 values[index] = value;
80 }
81
82 public PrimitiveType getLength(){
83
84 return new PrimitiveType(values.length);
85 }
86
87 public String toString(){
88 return "ArrayInstance: "+values;
89 }
90 }
This page was automatically generated by Maven